package com.atguigu.rabbitmqtest.dead_exchange;

import com.atguigu.rabbitmqtest.utils.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

public class ProducerTTL {
    private static final String NORMAL_EXCHANGE = "normal_exchange";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
        for (int i = 1; i <= 10; i++) {
            String message = "发送的消息是"+i;
            //设置消息的 TTL 时间
            AMQP.BasicProperties properties =
                    new AMQP.BasicProperties().builder().expiration("10000").build();
            channel.basicPublish(NORMAL_EXCHANGE, "zhangsan", properties, message.getBytes("UTF-8"));
            System.out.println("生产者发送消息:"+message);
        }
    }
}
